﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using JTC.Genetics.Molecules;
using Moq;
using JTC.Genetics.Molecules.Proteins;
using JTC.Genetics.Molecules._Abstract;
using JTC.Genetics.Molecules._Interfaces;
using JTC.Genetics.Molecules.Proteins._Abstract;
using JTC.Genetics.Replication._Interfaces;

namespace JTC.Genetics.UnitTests
{
    [TestClass]
    public class Chromosomes_Tests
    {
        private IChromosomes _instance;
        private Mock<ProteinBase> _mockProtien;
        private Mock<ITranslator> _mockTranslator;

        [TestInitialize]
        public void SetUp()
        {
            _instance = new Chromosomes();
            _mockTranslator = new Mock<ITranslator>();
        }

        [TestMethod]
        public void Implements_IChromosomes()
        {
            IChromosomes _instance = new Chromosomes();

            Assert.IsInstanceOfType(_instance, typeof(IChromosomes));
        }

        [TestMethod]
        public void can_add_Autosome()
        {
            // Arrange 

            _mockProtien = new Mock<ProteinBase>();

            // Act

            _instance.Add(new Autosome(_mockProtien.Object, _mockTranslator.Object));

            // Assert

            Assert.AreEqual(1, _instance.Count);
        }

        [TestMethod]
        public void can_add_Multiple_Chromosome()
        {
            // Arrange 

            _mockProtien = new Mock<ProteinBase>();

            // Act

            _instance.Add(new Autosome(_mockProtien.Object, _mockTranslator.Object));
            _instance.Add(new Autosome(_mockProtien.Object, _mockTranslator.Object));

            // Assert

            Assert.AreEqual(2, _instance.Count);
        }

        [TestMethod]
        public void can_Clear_Chromosomes()
        {

            // Arrange 

            _mockProtien = new Mock<ProteinBase>();

            _instance.Add(new Autosome(_mockProtien.Object, _mockTranslator.Object));
            _instance.Add(new Autosome(_mockProtien.Object, _mockTranslator.Object));

            // Act

            _instance.Clear();

            // Assert

            Assert.AreEqual(0, _instance.Count);
        }

        [TestMethod]
        public void can_Remove_Chromosomes()
        {
            // Arrange 

            _mockProtien = new Mock<ProteinBase>();

            var p1 = new Autosome(_mockProtien.Object, _mockTranslator.Object);
            var p2 = new Autosome(_mockProtien.Object, _mockTranslator.Object);

            _instance.Add(p1);
            _instance.Add(p2);

            // Act

            _instance.Remove(p1);

            // Assert

            Assert.AreEqual(1, _instance.Count);
        }

        [TestMethod]
        public void can_CopyTo_Chromosomes()
        {

            // Arrange 

            _mockProtien = new Mock<ProteinBase>();

            Autosome[] array = new Autosome[4];

            var p1 = new Autosome(_mockProtien.Object, _mockTranslator.Object);
            var p2 = new Autosome(_mockProtien.Object, _mockTranslator.Object);

            _instance.Add(p1);
            _instance.Add(p2);

            // Act

            _instance.CopyTo(array, 1);

            // Assert

            Assert.AreEqual(4, array.Length);
            Assert.IsNull(array[0]);
            Assert.IsNotNull(array[1]);
            Assert.IsNotNull(array[2]);
            Assert.IsNull(array[3]);
        }
    }
}
